<template>
  <el-card>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="商品名称">
        <el-input v-model="form.goodsName"></el-input>
      </el-form-item>
      <el-form-item label="商品类型">
        <el-select v-model="form.category" placeholder="请选择商品类型">
          <el-option label="文学" value="1"></el-option>
          <el-option label="流行" value="2"></el-option>
          <el-option label="文化" value="3"></el-option>
          <el-option label="生活" value="4"></el-option>
          <el-option label="经管" value="5"></el-option>
          <el-option label="科技" value="6"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品售价">
       <el-input-number v-model="form.price" :precision="2" :min="0.1"></el-input-number>
      </el-form-item>
      <el-form-item label="商品数量">
         <el-input-number v-model="form.number" :min="1" label="描述文字"></el-input-number>
      </el-form-item>
      <el-form-item label="商品状态">
        <el-select v-model="form.state" placeholder="商品状态">
          <el-option label="新品" value="true"></el-option>
          <el-option label="二手" value="false"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品封面">
        <el-input v-model="form.photo"></el-input>
      </el-form-item>
      <el-form-item label="商品简介">
        <el-input type="textarea" v-model="form.summary"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>
<script>
  export default {
    data() {
      return {
        form: {
            goodsName:'',
            category:'',
            price:'',
            number:'',
            state:'',
            photo:'',
            summary:'',
        }
      }
    },
    methods: {
      onSubmit() {
          this.$axios.post('/addGoods',{
            goodsName:this.form.goodsName,
            photo:this.form.photo,
            price:this.form.price,
            category:this.form.category,
            number:this.form.number,
            summary:this.form.summary,
            state:this.form.state
          }).then(resp => {
           if(resp.data.code === 200){
             alert("添加成功")
           }
           if(resp.data.code === 300){
             alert("请勿重复添加")
           }
          })
      }
    }
  }
</script>
